#include "ZigbusOrder.h"
#include <QDebug>
ZigbusOrder::ZigbusOrder()
    : ZigbusItem(-1, ORDER_SIZE)
{
}

ZigbusOrder::ZigbusOrder(int value)
    : ZigbusItem(value, ORDER_SIZE)
{
}

ZigbusOrder::ZigbusOrder(const QString &str)
    : ZigbusItem(-1, ORDER_SIZE)
{
    if(str == "off" || str == "disable") setValue(ORDER_OFF);
    else if(str == "on" || str == "enable") setValue(ORDER_ON);
    else if(str == "toggle") setValue(ORDER_TOGGLE);
    else if(str == "servo") setValue(ORDER_SERVO);
    else if(str == "text") setValue(ORDER_TEXT);
    else if(str == "pwm") setValue(ORDER_PWM);
    else if(str == "heater") setValue(ORDER_HEATER);
    else if(str == "state") setValue(ORDER_STATE);
    else if(str == "serial") setValue(ORDER_SERIAL);
    else if(str == "remote") setValue(ORDER_REMOTE);
    else if(str == "ping") setValue(ORDER_PING);
    else if(str == "meteo") setValue(ORDER_METEO);
    else if(str == "config") setValue(ORDER_CONFIG);
    else if(str == "init") setValue(ORDER_INIT);
    else if(str == "reboot") setValue(ORDER_REBOOT);
    else if(str == "tie") setValue(ORDER_TIE);
    else {
        qDebug() << "unknown order " << str;
    }
}

ZigbusOrder::ZigbusOrder(const ZigbusOrder &other)
    : ZigbusItem(other)
{
}

ZigbusOrder::~ZigbusOrder()
{
}

QString ZigbusOrder::text() const
{
    switch(getValue()) {
    case ORDER_OFF: return "off";
    case ORDER_ON: return "on";
    case ORDER_TOGGLE: return "toggle";
    case ORDER_SERVO: return "servo";
    case ORDER_TEXT: return "text";
    case ORDER_PWM:return "pwm";
    case ORDER_HEATER:return "heater";
    case ORDER_STATE:return "state";
    case ORDER_SERIAL:return "serial";
    case ORDER_REMOTE:return "remote";
    case ORDER_PING:return "ping";
    case ORDER_METEO:return "meteo";
    case ORDER_CONFIG:return "config";
    case ORDER_INIT:return "init";
    case ORDER_REBOOT:return "reboot";
    case ORDER_TIE: return "tie";
    default: return "undefined";
    }
}
